// 碳排放总量占比
import * as echarts from 'echarts';
// import {Table} from 'antd';
export const pieTwo = (dataInfo = []) => {
  let colorList = [
    '#2391ff',
    '#5ad8a6',
    '#99d8f2',
    '#ffdf25',
    '#f45d41',
    '#c896f9',
    '#657798',
    '#d4557b',
    '#f1627a',
  ];
  let num;
  if (dataInfo) {
    num = dataInfo.reduce((n, i) => {
      return (n += Number(i.carb));
    }, 0);
  }
  return {
    // tooltip: {
    //   trigger: 'item',
    // },
    color: colorList,
    series: [
      {
        name: '11',
        type: 'pie',
        radius: '55%',
        center: ['50%', '50%'],
        data:
          dataInfo &&
          dataInfo.map((item) => ({ name: item.areaName, value: item.carb })),
        roseType: 'radius',
        label: {
          show: true,
          formatter: function (e) {
            return (
              e.name + ' ' + ((Number(e.value) / num) * 100).toFixed(2) + '%'
            );
          },
        },
        labelLine: {
          lineStyle: {
            show: true,
          },
        },
        smooth: 0.1,
        length: 10,
        length2: 20,
      },
    ],
  };
};
//碳排放总量趋势
export const stackBarOption = (dataInfo = [], tooltipName) => {
  let xAxisData = [];
  let yAxisBar = [];
  let yAxisLine = [];
  if (!!dataInfo) {
    dataInfo.forEach((item) => {
      xAxisData.push(item?.cycle);
      yAxisBar.push(((item?.sumMoniiVo.carb || 0) / 10000).toFixed(2));
      yAxisLine.push((item?.sumMoniiVo.carbGrowRat || 0).toFixed(2));
    });
  }
  let colorList = [
    '#f5a843',
    // '#fad3a0',
    '#92fefe',
    '#5b8ff9',
    '#5ad8a6',
    '#caf982',
    '#b8741a',
  ];
  let option = {
    color: colorList,
    legend: {
      icon: 'rect',
      itemHeight: 6,
      itemWidth: 15,
      left: '35%',
      top: '8%',
    },
    tooltip: {
      trigger: 'axis',
    },
    grid: {
      left: '3%',
      right: '4%',
      bottom: '3%',
      top: '20%',
      containLabel: true,
    },
    xAxis: [
      {
        type: 'category',
        boundaryGap: ['20%', '20%'],
        data: xAxisData,
      },
    ],
    yAxis: [
      {
        name: '单位： 亿吨CO2',
        type: 'value',
        axisLabel: {
          // 坐标轴标签样式设置
          textStyle: { fontSize: 10 },
          formatter: '{value} ', // 给坐标轴标签加单位
        },
        nameTextStyle: { fontSize: 10 },
      },
      {
        // name: '增长率(%)',
        type: 'value',
        position: 'right',
        formatter: '{value}%',
        axisLabel: {
          textStyle: { fontSize: 10 },
          formatter: '{value} %', // 给坐标轴标签加单位
        },
        nameTextStyle: { fontSize: 10 },
        itemStyle: {
          color: '#ffd07a',
        },
      },
    ],
    series: [
      {
        name: '碳排放量',
        type: 'bar',
        barWidth: '30%',
        data: yAxisBar,
        // tooltip: {
        //   valueFormatter: function (value) {},
        // },
      },
      {
        name: '同比变化率',
        type: 'line',
        yAxisIndex: 1,
        data: yAxisLine,
        tooltip: {
          valueFormatter: function (value) {
            return value + '%';
          },
        },
      },
    ],
  };
  return option;
};

// 碳排放与GDP关联分析
export const stackOption = (dataInfo = [], type) => {
  let xAxisData = [];
  let yAxis1 = [];
  let yAxis2 = [];
  let xAxisName1 = '';
  let xAxisName2 = '';
  let name1 = '';
  let name2 = '';
  if (type == 1 && !!dataInfo) {
    dataInfo.forEach((item) => {
      xAxisData.push(item?.cycle);
      yAxis1.push(((item?.sumMoniiVo.carb || 0) / 10000).toFixed(2));
      yAxis2.push(((item?.sumMoniiVo.gdp || 0) / 10000).toFixed(2));
    });
    xAxisName1 = '亿吨CO₂';
    xAxisName2 = '亿美元';
    name1 = '碳排放量';
    name2 = 'GPD';
  } else if (type == 2 && !!dataInfo) {
    xAxisName1 = '吨CO₂/万元';
    xAxisName2 = '万美元';
    name1 = '碳排放强度';
    name2 = '人均GPD';
    dataInfo.forEach((item) => {
      xAxisData.push(item?.cycle);
      yAxis1.push((item?.sumMoniiVo.carbStrh || 0).toFixed(2));
      yAxis2.push((item?.sumMoniiVo.perGdp || 0).toFixed(2));
    });
  }
  let colorList = [
    '#92fefe',
    '#f5a843',
    // '#fad3a0',
    '#5b8ff9',
    '#5ad8a6',
    '#caf982',
    '#b8741a',
  ];
  let option = {
    color: colorList,
    legend: {
      icon: 'rect',
      itemHeight: 6,
      itemWidth: 15,
      left: '35%',
      top: '8%',
    },
    tooltip: {
      trigger: 'axis',
    },
    grid: {
      left: '3%',
      right: '4%',
      bottom: '3%',
      top: '20%',
      containLabel: true,
    },
    xAxis: [
      {
        type: 'category',
        boundaryGap: ['20%', '20%'],
        data: xAxisData,
      },
    ],
    yAxis: [
      {
        name: `单位： ${xAxisName1}`,
        type: 'value',
        // min: 0,
        // max: 100,
        axisLabel: {
          // 坐标轴标签样式设置
          textStyle: { fontSize: 10 },
          formatter: '{value} ', // 给坐标轴标签加单位
        },
        nameTextStyle: { fontSize: 10, align: 'left' },
      },
      {
        name: `单位：${xAxisName2}`,
        type: 'value',
        // min: 0,
        // max: 10,
        position: 'right',
        formatter: '{value}%',
        axisLabel: {
          textStyle: { fontSize: 10 },
          // formatter: '{value} %', // 给坐标轴标签加单位
        },
        nameTextStyle: { fontSize: 10 },
        itemStyle: {
          color: '#ffd07a',
        },
      },
    ],
    series: [
      {
        name: name1,
        type: 'line',
        data: yAxis1,
      },
      {
        name: name2,
        type: 'line',
        yAxisIndex: 1,
        data: yAxis2,
      },
    ],
  };
  return option;
};

// 能源消费类型占比分析
export const doublePie = (dataInfo = [], type) => {
  if (!dataInfo) return {};
  let energyType = ['化石能源', '石油', '煤炭', '天然气'];
  let fossilNum;
  let allNum;
  let isenergyType = [];
  dataInfo.map((ele) => {
    if (!energyType.includes(ele.energyName)) {
      isenergyType.push(ele.energyName);
    }
  });
  isenergyType.unshift('非化石能源');
  if (type == 1) {
    fossilNum = dataInfo.reduce((n, i) => {
      if (!energyType.includes(i.energyName)) return (n += 0);
      return (n += i.energy / 10000);
    }, 0);
    allNum = dataInfo.reduce((n, i) => {
      return (n += i.energy / 10000);
    }, 0);
  } else if (type == 2) {
    fossilNum = dataInfo.reduce((n, i) => {
      if (!energyType.includes(i.energyName)) return (n += 0);
      return (n += i.secdEnrg / 10000);
    }, 0);
    allNum = dataInfo.reduce((n, i) => {
      return (n += i.secdEnrg / 10000);
    }, 0);
  }
  let colorList = [
    '#e27e8a',
    '#db56b0',
    '#2391ff',
    '#5ad8a6',
    '#99d8f2',
    '#ffdf25',
    '#f45d41',
    '#c896f9',
    '#657798',
    '#d4557b',
    '#f1627a',
  ];
  return {
    tooltip: {
      trigger: 'item',
      formatter: '{b}<br/>能源占比： {d}%',
    },
    legend: [
      {
        orient: 'vertical',
        top: '20%',
        left: '55%',
        icon: 'circle',
        textStyle: {
          align: 'left',
          verticalAlign: 'middle',
          rich: {
            name: {
              color: 'rgba(0,0,0,0.5)',
              fontSize: 10,
            },
            value: {
              color: 'rgba(0,0,0,0.5)',
              fontSize: 10,
            },
            rate: {
              color: 'rgba(0,0,0,0.9)',
              fontSize: 10,
            },
          },
        },
        data: energyType,
        formatter: (name) => {
          return `{name|${name}}`;
        },
      },
      {
        orient: 'vertical',
        top: '20%',
        left: '75%',
        icon: 'circle',
        textStyle: {
          align: 'left',
          verticalAlign: 'middle',
          rich: {
            name: {
              color: 'rgba(0,0,0,0.5)',
              fontSize: 10,
            },
            value: {
              color: 'rgba(0,0,0,0.5)',
              fontSize: 10,
            },
            rate: {
              color: 'rgba(0,0,0,0.9)',
              fontSize: 10,
            },
          },
        },
        data: isenergyType,
        formatter: (name) => {
          return `{name|${name}}`;
        },
      },
    ],
    color: colorList,
    series: [
      {
        name: '能源占比',
        type: 'pie',
        radius: ['0%', '30%'],
        center: ['25%', '50%'],
        itemStyle: {
          normal: {
            label: {
              show: false,
            },
          },
          opacity: 0.8,
        },
        label: {
          normal: {
            position: 'inner',
          },
        },
        data: [
          {
            name: '化石能源',
            value: ((fossilNum / allNum) * 100).toFixed(2),
          },
          {
            name: '非化石能源',
            value: 100 - ((fossilNum / allNum) * 100).toFixed(2),
          },
        ],
      },
      {
        name: '能源类型',
        type: 'pie',
        radius: ['45%', '65%'],
        center: ['25%', '50%'],
        itemStyle: {
          normal: {
            label: {
              show: false,
            },
          },
          opacity: 0.8,
        },
        label: {
          normal: {
            position: 'inner',
          },
        },
        data: dataInfo.map((item) => ({
          name: item.energyName,
          value: (item.energy / 1).toFixed(2),
        })),
      },
    ],
  };
};
// 能源消费类型占比分析详情
export const doublePieDetails = (dataInfo = [], type) => {
  if (!dataInfo) return {};
  let energyType = ['化石能源', '石油', '煤炭', '天然气'];
  let fossilNum;
  let allNum;
  let dataList;
  if (type == 1) {
    fossilNum = dataInfo.reduce((n, i) => {
      if (!energyType.includes(i.energyName)) return (n += 0);
      return (n += i.energy / 1);
    }, 0);
    allNum = dataInfo.reduce((n, i) => {
      return (n += i.energy / 1);
    }, 0);
    dataList = dataInfo.map((item) => ({
      name: item.energyName,
      value: (item.energy / 1).toFixed(2),
      tage: ((item.energy / allNum) * 100).toFixed(2),
    }));
  } else if (type == 2) {
    fossilNum = dataInfo.reduce((n, i) => {
      if (!energyType.includes(i.energyName)) return (n += 0);
      return (n += i.secdEnrg / 1);
    }, 0);
    allNum = dataInfo.reduce((n, i) => {
      return (n += i.secdEnrg / 1);
    }, 0);
    dataList = dataInfo.map((item) => ({
      name: item.energyName,
      value: (item.secdEnrg / 1).toFixed(2),
      tage: ((item.secdEnrg / allNum) * 100).toFixed(2),
    }));
  }
  let colorList = [
    '#e27e8a',
    '#db56b0',
    '#2391ff',
    '#5ad8a6',
    '#99d8f2',
    '#ffdf25',
    '#f45d41',
    '#c896f9',
    '#657798',
    '#d4557b',
    '#f1627a',
  ];

  dataList.unshift(
    {
      name: '化石能源',
      value: fossilNum.toFixed(2),
      tage: ((fossilNum / allNum) * 100).toFixed(2),
    },
    {
      name: '非化石能源',
      value: (allNum - fossilNum).toFixed(2),
      tage: (100 - (fossilNum / allNum) * 100).toFixed(2),
    },
  );
  return {
    tooltip: {
      trigger: 'item',
      formatter: '{b}<br/>能源占比： {d}%',
    },
    legend: {
      orient: 'vertical',
      top: '10%',
      left: '45%',
      icon: 'circle',
      textStyle: {
        align: 'left',
        verticalAlign: 'middle',
        lineHeight: 40,
        rich: {
          name: {
            color: 'rgba(0,0,0,0.5)',
            fontSize: 16,
            width: 140,
            height: 40,
            // padding: 20,
          },
          rate: {
            color: 'rgba(0,0,0,0.5)',
            fontSize: 16,
            width: 120,
            align: 'right',
            // padding: 20,
            height: 40,
          },
          value: {
            color: 'rgba(0,0,0,0.5)',
            fontSize: 16,
            width: 260,
            align: 'right',
            // padding: 20,
            height: 40,
          },
        },
      },
      formatter: (name) => {
        for (let i = 0; i < dataList.length; i++) {
          if (name == dataList[i].name) {
            return `{name|${name}}{rate|${dataList[i].tage}%}{value|${dataList[i].value}万吨标煤}`;
          }
        }
      },
    },
    color: colorList,
    series: [
      {
        name: '能源占比',
        type: 'pie',
        radius: ['0%', '30%'],
        center: ['25%', '50%'],
        itemStyle: {
          normal: {
            label: {
              show: false,
            },
          },
          opacity: 0.8,
        },
        label: {
          normal: {
            position: 'inner',
          },
        },
        data: [
          {
            name: '化石能源',
            value: ((fossilNum / allNum) * 100).toFixed(2),
          },
          {
            name: '非化石能源',
            value: 100 - ((fossilNum / allNum) * 100).toFixed(2),
          },
        ],
      },
      {
        name: '能源类型',
        type: 'pie',
        radius: ['45%', '65%'],
        center: ['25%', '50%'],
        itemStyle: {
          normal: {
            label: {
              show: false,
            },
          },
          opacity: 0.8,
        },
        label: {
          normal: {
            position: 'inner',
          },
        },
        data: dataInfo.map((item) => ({
          name: item.energyName,
          value: (item.energy / 1).toFixed(2),
        })),
      },
    ],
  };
};
/**
 * 环形图
 * @param {array} data [{name:xx, value:xx}]
 * @param {string} title 图表名称
 * @param {string} allName 总数量，总用电量等
 * @param {string} unit 数学单位
 * @returns options对象
 */
export const DoughnutChart = (
  data = [
    { name: 'z1', value: 1 },
    { name: 'z2', value: 1 },
    { name: 'z3', value: 1 },
  ],
  title = '能源消费行业占比分析',
  allName = '总数量',
  unit = '(万吨标煤)',
) => {
  if (!data) return;
  let num = data.reduce((n, i) => {
    return (n += i.energy / 1);
  }, 0);
  let colorList = [
    '#2391ff',
    '#5ad8a6',
    '#99d8f2',
    '#ffdf25',
    '#f45d41',
    '#c896f9',
    '#657798',
    '#d4557b',
    '#f1627a',
  ];
  return {
    color: colorList,
    tooltip: {
      trigger: 'item',
    },
    graphic: {
      type: 'text',
      left: '24%',
      top: '45%',
      style: {
        text: allName + unit + '\n\n' + num.toFixed(2),
        textAlign: 'center',
        fill: '#333',
        width: 30,
        height: 30,
        fontSize: 12,
      },
    },
    legend: {
      orient: 'vertical',
      top: '20%',
      right: '15%',
      icon: 'circle',
      textStyle: {
        align: 'left',
        verticalAlign: 'middle',
        rich: {
          name: {
            color: 'rgba(0,0,0,0.5)',
            fontSize: 12,
          },
          value: {
            color: 'rgba(0,0,0,0.5)',
            fontSize: 12,
          },
          rate: {
            color: 'rgba(0,0,0,0.9)',
            fontSize: 12,
          },
        },
      },
      formatter: (name) => {
        if (data.length) {
          const item = data.filter((item) => item.name === name)[0];
          return `{name|${name}}`;
        }
      },
    },
    series: [
      {
        name: title,
        type: 'pie',
        radius: ['40%', '65%'],
        center: ['35%', '50%'],
        avoidLabelOverlap: false,
        label: {
          normal: {
            show: false,
            formatter: '{d}%',
            position: 'inside',
          },
        },
        itemStyle: {
          borderWidth: 2, //设置border的宽度有多大
          borderColor: '#fff',
        },
        labelLine: {
          show: false,
        },
        data: data.map((item) => ({
          name: item.name,
          value: (item.energy / 1).toFixed(2),
        })),
      },
    ],
  };
};
export const DoughnutChartDetails = (
  data = [],
  title = '能源消费行业占比分析',
  allName = '总数量',
  unit = '(万吨标煤)',
) => {
  if (!data) return;
  let num = data.reduce((n, i) => {
    return (n += i.energy / 1);
  }, 0);
  let dataList = data.map((item) => ({
    name: item.name,
    value: (item.energy / 1).toFixed(2),
    rate: ((item.energy / num) * 100).toFixed(2),
  }));
  let colorList = [
    '#2391ff',
    '#5ad8a6',
    '#99d8f2',
    '#ffdf25',
    '#f45d41',
    '#c896f9',
    '#657798',
    '#d4557b',
    '#f1627a',
  ];
  return {
    color: colorList,
    tooltip: {
      trigger: 'item',
    },
    graphic: {
      type: 'text',
      left: '20%',
      top: '45%',
      style: {
        text: allName + unit + '\n\n' + num.toFixed(2),
        textAlign: 'center',
        fill: '#333',
        width: 30,
        height: 30,
        fontSize: 22,
      },
    },
    legend: {
      orient: 'vertical',
      top: '10%',
      left: '45%',
      icon: 'circle',
      textStyle: {
        align: 'left',
        verticalAlign: 'middle',
        lineHeight: 40,
        rich: {
          name: {
            color: 'rgba(0,0,0,0.5)',
            fontSize: 16,
            width: 140,
            height: 40,
          },
          rate: {
            color: 'rgba(0,0,0,0.5)',
            fontSize: 16,
            width: 120,
            align: 'right',
            height: 40,
          },
          value: {
            color: 'rgba(0,0,0,0.5)',
            fontSize: 16,
            width: 260,
            align: 'right',
            height: 40,
          },
        },
      },
      formatter: (name) => {
        for (let i = 0; i < dataList.length; i++) {
          if (name == dataList[i].name) {
            return `{name|${name}}{rate|${dataList[i].rate}%}{value|${dataList[i].value}万吨标煤}`;
          }
        }
      },
    },
    series: [
      {
        name: title,
        type: 'pie',
        radius: ['40%', '65%'],
        center: ['25%', '50%'],
        avoidLabelOverlap: false,
        label: {
          normal: {
            show: false,
            formatter: '{d}%',
            position: 'inside',
          },
        },
        itemStyle: {
          borderWidth: 2, //设置border的宽度有多大
          borderColor: '#fff',
        },
        labelLine: {
          show: false,
        },
        data: data.map((item) => ({
          name: item.name,
          value: (item.energy / 1).toFixed(2),
        })),
      },
    ],
  };
};
export const carbonFlow = (dataInfo = []) => {
  let nameData = [];
  let linkData = [];
  let colorList = [
    '#2391ff',
    '#5ad8a6',
    '#99d8f2',
    '#ffdf25',
    '#f45d41',
    '#c896f9',
    '#657798',
    '#d4557b',
    '#f1627a',
    '#7ba5fa',
    '#d1dcf3',
    '#7bdfb7',
    '#8b7efa',
    '#8ad3ef',
    '#ffac6a',
  ];
  if (!!dataInfo) {
    dataInfo.forEach((ele) => {
      ele.anlsVos.forEach((item) => {
        if (!nameData.includes(item.sourceName)) {
          nameData.push(item.sourceName);
        }
        // if (item.numericalValue > 0 && item.targetName != '') {
        linkData.push({
          source: item.sourceName,
          target: item.targetName,
          value: parseFloat(item.numericalValue).toFixed(2),
        });
        // }
      });
    });
  }
  return {
    tooltip: {
      trigger: 'item',
    },
    animation: false,
    series: [
      {
        type: 'sankey',
        bottom: '10%',
        nodeWidth: 5,
        nodeGap: 20,
        left: '10%',
        right: '10%',
        emphasis: {
          focus: 'adjacency',
        },
        data: nameData.map((ele, i) => ({
          name: ele,
          itemStyle: { color: colorList[i], borderColor: colorList[i] },
        })),
        links: linkData,
        focusNodeAdjacency: 'allEdges',
        itemStyle: {
          borderWidth: 0,
        },
        label: {
          position: 'bottom',
          color: '#748AA1',
        },
        lineStyle: {
          color: 'source',
          curveness: 0.5,
        },
      },
    ],
  };
};

//主要国家碳排放排名
export const carbonRank = (dataInfo = [], type) => {
  let xAxisData = [];
  let yAxis1 = [];
  let yAxis2 = [];
  let xAxisName1 = '';
  let name1 = '';
  let name2 = '';
  if (type == 1 && !!dataInfo){
    dataInfo.forEach((item)=>{
      xAxisData.push(item.areaName);
      yAxis1.push((item.moData));
      yAxis2.push((item.publicData));
    })
    xAxisName1 = '亿吨CO₂';
    name1 = '模型计算数据';
    name2 = '公开数据（EI）';
  }else if (type == 2 && !!dataInfo){
    dataInfo.forEach((item)=>{
      xAxisData.push(item.areaName);
      yAxis1.push((item.moData));
      yAxis2.push((item.publicData));
    })
    xAxisName1 = '吨CO₂/万元';
    name1 = '模型计算数据';
    name2 = '公开数据（IEA）';
  }else if (type == 3 && !!dataInfo){
    dataInfo.forEach((item)=>{
      xAxisData.push(item.areaName);
      yAxis1.push((item.moData));
      yAxis2.push((item.publicData));
    })
    xAxisName1 = '吨CO₂/人';
    name1 = '模型计算数据';
    name2 = '公开数据（IEA）';
  }
  let colorList = [
    '#2391ff',
    '#5ad8a6',
    '#99d8f2',
    '#ffdf25',
    '#f45d41',
    '#c896f9',
    '#657798',
    '#d4557b',
    '#f1627a',
  ];
  let option = {
    color: colorList,
    legend: {
      icon: 'rect',
      itemHeight: 6,
      itemWidth: 15,
      left: '35%',
      top: '8%',
    },
    tooltip: {
      trigger: 'axis',
    },
    xAxis: {
      type: 'category',
      axisLabel: {
        // 坐标轴标签样式设置
        textStyle: { fontSize: 10 },
        interval: 0, //显示所有标签
        rotate: 45, //文字过长可以旋转
      },
      data:xAxisData,
    },
    grid: {
      left: '3%',
      right: '4%',
      bottom: '3%',
      top: '20%',
      containLabel: true,
    },
    yAxis: {
      name: `单位： ${xAxisName1}`,
      type: 'value',
      axisLabel: {
        // 坐标轴标签样式设置
        textStyle: { fontSize: 10 },
        formatter: '{value} ', // 给坐标轴标签加单位
      },
    },
    series: [
      {
        name: name1,
        type: 'bar',
        barWidth: '30%',
        data:yAxis1,
      },
      {
        name: name2,
        type: 'bar',
        barWidth: '30%',
        data:yAxis2,
      },
    ],
  };
  return option;
};
export const carbonTime = (dataInfo = []) => {
  let yLabel = [];
  let gData = [];
  let zData = [];
  if(!!dataInfo){
    dataInfo.forEach((item)=>{
      yLabel.push(item.areaName)
      gData.push(item.peakYear)
      zData.push(item.nutrYear)
    })
  }
  let bgData = [];
  for (let i in gData) {
    bgData.push(5000);
  }
  let option = {
    // color: ['#08daaa','#6571fc'],
    tooltip: {
      trigger: 'axis',
      axisPointer: {
        type: 'none',
      },
    },
    legend: {
      data: ['碳达峰时间', '碳中和时间'],
    },
    grid: {
      left: '3%',
      right: '4%',
      bottom: '3%',
      top: '10%',
      containLabel: true,
    },
    xAxis: {
      type: 'value',
      show: true,
      data: [1990, 2010, 2030, 2050, 2070],
    },
    yAxis: {
      type: 'category',
      inverse: true,
      // axisLabel:{
      //   show:true,
      //   margin:15,
      //   textStyle:{
      //     color:'#fff',
      //   }
      // },
      axisLine: {
        show: false,
      },
      axisTick: {
        show: false,
      },
      data: yLabel,
    },
    series: [
      {
        name: '碳达峰时间',
        type: 'bar',
        stack: 'total',
        zlevel: 2030,
        itemStyle: {
          normal: {
            label: {
              show: true,
              position: 'top',
              distance: -6,
              textStyle: {
                fontSize: 10,
              },
            },
            barBorderRadius: [0, 0, 0, 0],
            //颜色渐变
            color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [
              {
                offset: 0,
                color: '#ccc',
              },
              {
                offset: 1,
                color: '#00d5fc',
              },
            ]),
            shadowBlur: 0,
            shadowColor: 'rgba(87,220,222,0.7)',
          },
        },
        barWidth: 15,
        data: gData,
      },
      {
        name: '碳中和时间',
        type: 'bar',
        zlevel: 1,
        stack: 'total',
        itemStyle: {
          normal: {
            label: {
              show: true,
              position: 'top',
              distance: -6,
              textStyle: {
                fontSize: 10,
              },
            },
            barBorderRadius: [0, 0, 0, 0],
            //颜色渐变
            color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [
              {
                offset: 0,
                color: '#94D8C8',
              },
              {
                offset: 1,
                color: '#81E0C7',
              },
            ]),
            shadowBlur: 0,
            shadowColor: 'rgba(87,220,222,0.7)',
          },
        },
        barWidth: 15,
        // barGap:'20%',
        data: zData,
      },
      //背景进度条
      {
        name: '背景',
        type: 'bar',
        barWidth: 15,
        barGap: '-100%',
        data: bgData,
        tooltip: {
          show: false,
        },
        itemStyle: {
          normal: {
            color: '#ccc',
          },
        },
      },
    ],
  };
  return option;
};
export const carbonContrast = (dataInfo = [], type) => {
  // let xAxisData = [];
  let yAxis1 = [];
  let yAxis2 = [];
  let xAxisName1 = '';
  let name1 = '';
  let name2 = '';
  if (type == 1 && !!dataInfo){
    dataInfo.forEach((item)=>{
      yAxis1.push((item.carbDisp));
      yAxis2.push((item.carbDevi));
    })
    xAxisName1 = '亿吨CO₂';
    name1 = '公共数据（EI）与模型碳排放偏差量';
    name2 = '偏差百分比';
  }else if (type == 2 && !!dataInfo){
    dataInfo.forEach((item)=>{
      yAxis1.push((item.carbDisp));
      yAxis2.push((item.carbDevi));
    })
    xAxisName1 = '亿吨CO₂';
    name1 = '公共数据（IEA）与模型碳排放偏差量';
    name2 = '偏差百分比';
  }else if (type == 3 && !!dataInfo){
    dataInfo.forEach((item)=>{
      yAxis1.push((item.carbDisp));
      yAxis2.push((item.carbDevi));
    })
    xAxisName1 = '亿吨CO₂';
    name1 = '公共数据（EIA）与模型碳排放偏差量';
    name2 = '偏差百分比';
  }
  let colorList = [
    '#2391ff',
    // '#fad3a0',
    'rgb(139 175 43)',
    '#5b8ff9',
    '#5ad8a6',
    '#caf982',
    '#b8741a',
  ];
  let option = {
    color: colorList,
    legend: {
      icon: 'rect',
      itemHeight: 6,
      itemWidth: 15,
      left: '35%',
      top: '3%',
    },
    tooltip: {
      trigger: 'axis',
    },
    grid: {
      left: '3%',
      right: '4%',
      bottom: '3%',
      top: '20%',
      containLabel: true,
    },
    xAxis: [
      {
        type: 'category',
        boundaryGap: ['20%', '20%'],
        data: [2017, 2018, 2019, 2020, 2021],
      },
    ],
    yAxis: [
      {
        name: `单位： ${xAxisName1}`,
        type: 'value',
        min: 0,
        max: 100,
        axisLabel: {
          // 坐标轴标签样式设置
          textStyle: { fontSize: 10 },
          formatter: '{value} ', // 给坐标轴标签加单位
        },
        nameTextStyle: { fontSize: 10 },
      },
      {
        // name: '增长率(%)',
        type: 'value',
        min: 0,
        max: 10,
        position: 'right',
        formatter: '{value}%',
        axisLabel: {
          textStyle: { fontSize: 10 },
          formatter: '{value} %', // 给坐标轴标签加单位
        },
        nameTextStyle: { fontSize: 10 },
        itemStyle: {
          color: '#ffd07a',
        },
      },
    ],
    series: [
      {
        name: name1,
        type: 'bar',
        barWidth: '30%',
        data: yAxis1,
      },
      {
        name: name2,
        type: 'line',
        yAxisIndex: 1,
        data: yAxis2,
      },
    ],
  };
  return option;
};
// export const carbonContrastText = () => {
//   let colorList = [
//     '#2391ff',
//     // '#fad3a0',
//     'rgb(139 175 43)',
//     '#5b8ff9',
//     '#5ad8a6',
//     '#caf982',
//     '#b8741a',
//   ];
//   let option = {
//     color: colorList,
//     legend: {
//       icon: 'rect',
//       itemHeight: 6,
//       itemWidth: 15,
//       left: '35%',
//       top: '3%',
//     },
//     tooltip: {
//       trigger: 'axis',
//     },
//     grid: {
//       left: '3%',
//       right: '4%',
//       bottom: '3%',
//       top: '20%',
//       containLabel: true,
//     },
//     xAxis: [
//       {
//         type: 'category',
//         boundaryGap: ['20%', '20%'],
//         data: [2017, 2018, 2019, 2020, 2021],
//       },
//     ],
//     yAxis: [
//       {
//         name: '单位： 亿吨CO2',
//         type: 'value',
//         min: 0,
//         max: 100,
//         axisLabel: {
//           // 坐标轴标签样式设置
//           textStyle: { fontSize: 10 },
//           formatter: '{value} ', // 给坐标轴标签加单位
//         },
//         nameTextStyle: { fontSize: 10 },
//       },
//       {
//         // name: '增长率(%)',
//         type: 'value',
//         min: 0,
//         max: 10,
//         position: 'right',
//         formatter: '{value}%',
//         axisLabel: {
//           textStyle: { fontSize: 10 },
//           formatter: '{value} %', // 给坐标轴标签加单位
//         },
//         nameTextStyle: { fontSize: 10 },
//         itemStyle: {
//           color: '#ffd07a',
//         },
//       },
//     ],
//     series: [
//       {
//         name: '公共数据（IEA）与模型碳排放偏差量',
//         type: 'bar',
//         barWidth: '30%',
//         data: [31, 13, 11, 32, 23],
//       },
//       {
//         name: '偏差百分比',
//         type: 'line',
//         yAxisIndex: 1,
//         data: [1, 2, 1, 8, 3],
//       },
//     ],
//   };
//   return option;
// };
// export const carbonContrastList = () => {
//   let colorList = [
//     '#2391ff',
//     // '#fad3a0',
//     'rgb(139 175 43)',
//     '#5b8ff9',
//     '#5ad8a6',
//     '#caf982',
//     '#b8741a',
//   ];
//   let option = {
//     color: colorList,
//     legend: {
//       icon: 'rect',
//       itemHeight: 6,
//       itemWidth: 15,
//       left: '35%',
//       top: '3%',
//     },
//     tooltip: {
//       trigger: 'axis',
//     },
//     grid: {
//       left: '3%',
//       right: '4%',
//       bottom: '3%',
//       top: '20%',
//       containLabel: true,
//     },
//     xAxis: [
//       {
//         type: 'category',
//         boundaryGap: ['20%', '20%'],
//         data: [2017, 2018, 2019, 2020, 2021],
//       },
//     ],
//     yAxis: [
//       {
//         name: '单位： 亿吨CO2',
//         type: 'value',
//         min: 0,
//         max: 100,
//         axisLabel: {
//           // 坐标轴标签样式设置
//           textStyle: { fontSize: 10 },
//           formatter: '{value} ', // 给坐标轴标签加单位
//         },
//         nameTextStyle: { fontSize: 10 },
//       },
//       {
//         // name: '增长率(%)',
//         type: 'value',
//         min: 0,
//         max: 10,
//         position: 'right',
//         formatter: '{value}%',
//         axisLabel: {
//           textStyle: { fontSize: 10 },
//           formatter: '{value} %', // 给坐标轴标签加单位
//         },
//         nameTextStyle: { fontSize: 10 },
//         itemStyle: {
//           color: '#ffd07a',
//         },
//       },
//     ],
//     series: [
//       {
//         name: '公共数据（EIA）与模型碳排放偏差量',
//         type: 'bar',
//         barWidth: '30%',
//         data: [31, 13, 11, 32, 23],
//       },
//       {
//         name: '偏差百分比',
//         type: 'line',
//         yAxisIndex: 1,
//         data: [1, 2, 1, 8, 3],
//       },
//     ],
//   };
//   return option;
// };
export const carbonAnalysis = (dataInfo = []) => {
  let xAxisName1 = '';
  let name1 = '';
  let name2 = '';
  let name3 = '';
  let name4 = '';
  let yAxis1 = [];
  let yAxis2 = [];
  let yAxis3 = [];
  if(!!dataInfo) {
    dataInfo.forEach((item)=>{
      yAxis1.push(item.commitAndModelDisp);
      yAxis2.push(item.commitCarb);
      yAxis3.push(item.modelCcarb);
    })
    xAxisName1 = '亿吨CO₂';
    name1 = '模型计算碳排放量';
    name2 = '模型预测';
    name3 = '历史碳排放流量（EI）';
    name4 = '未来承诺碳排放目标'
  }
  let option = {
    tooltip: {
      trigger: 'axis',
      // formatter(params, ticket, callback) {
      //   let htmlStr = '';
      //   const valMap = {};
      //   const paramsFilter = params.filter((item) => item?.value && item);
      //   for (let i = 0; i < paramsFilter.length; i++) {
      //     const param = paramsFilter[i];
      //     const xName = param.name; //x轴名称
      //     const { seriesName } = param; //图例名称
      //     const { value } = param; //y轴值
      //     const { color } = param; //图例颜色
      //     if (i === 0) {
      //       htmlStr += `${xName}<br/>`; //x轴的名称
      //     }
      //     htmlStr += '<div>';
      //     htmlStr += `<span style="margin-right:5px;display:inline-block;width:10px;height:10px;border-radius:5px;background-color:${color};"></span>`;
      //     //原点后面显示的文本
      //     htmlStr += `${seriesName}: ${value}`;
      //     htmlStr += '</div>';
      //     valMap[seriesName] = value;
      //   }
      //   return htmlStr;
      // },
    },
    // legend: {
    //   data: [
    //     '模型计算碳排放量',
    //     '模型预测',
    //     '历史碳排放量(El)',
    //     '未来承诺碳排放目标',
    //   ],
    // },
    legend: {
      icon: 'rect',
      itemHeight: 6,
      itemWidth: 15,
      left: '35%',
      // top: '8%',
    },
    grid: {
      left: '3%',
      right: '4%',
      bottom: '3%',
      // top: '10%',
      containLabel: true,
    },
    xAxis: {
      axisLine: { onZero: false, show: false, lineStyle: {} }, //x周横线
      boundaryGap: false,
      data: [1970, 1990, 2010, 2030, 2050],
    },
    yAxis: {
      name: `单位： ${xAxisName1}`,
      type: 'value',
    },
    series: [
      {
        symbol: 'none',
        name: name1,
        type: 'line',
        // data: [40, 55, 45],
        data:yAxis3,
      },
      {
        name: name2,
        type: 'line',
        smooth: false,
        lineStyle: {
          width: 2,
          type: 'dotted',
        },
        // data: [null, null, 45, 33],
        data:yAxis1,
      },
      {
        name: name3,
        type: 'line',
        // data: [35, 45, 38],
        data:yAxis1,
      },
      {
        name: name4,
        type: 'line',
        smooth: false,
        lineStyle: {
          width: 2,
          type: 'dotted',
        },
        // data: [null, null, 38, 10],
        data:yAxis2,
      },
    ],
  };
  return option;
};

export const comparisonDatabases = (dataInfo = []) => {
  let yAxis1 = [];
  let yAxis2 = [];
  let yAxis3 = [];
  let yAxis4 = [];
  if(!!dataInfo){
    dataInfo.forEach((item)=>{
      yAxis1.push((item.moData));
      yAxis2.push((item.eiData));
      yAxis3.push((item.eiaData));
      yAxis4.push((item.ieaData));
    })
  }
  let option = {
    tooltip: {
      trigger: 'axis',
    },
    legend: {
      data: ['模型计算值', 'EI', 'EIA', 'IEA'],
    },
    grid: {
      left: '3%',
      right: '4%',
      bottom: '3%',
      // top: '20%',
      containLabel: true,
    },
    xAxis: {
      type: 'category',
      boundaryGap: ['20%', '20%'],
      data: [2009, 2011, 2013, 2015, 2017, 2019, 2021, 2023],
    },
    yAxis: {
      type: 'value',
      name: '单位:亿吨CO2',
    },
    series: [
      {
        name: '模型计算值',
        type: 'line',
        stack: '总量',
        // data: [110, 120, 96, 124, 90, 130, 110, 120],
        data:yAxis1,
      },
      {
        name: 'EI',
        type: 'line',
        stack: '总量',
        lineStyle: {
          width: 2,
          type: 'dotted',
        },
        // data: [120, 132, 101, 134, 90, 230, 210, 120],
        data:yAxis2,
      },
      {
        name: 'EIA',
        type: 'line',
        stack: '总量',
        lineStyle: {
          width: 2,
          type: 'dotted',
        },
        // data: [220, 182, 191, 234, 290, 330, 310, 220],
        data:yAxis3,
      },
      {
        name: 'IEA',
        type: 'line',
        stack: '总量',
        lineStyle: {
          width: 2,
          type: 'dotted',
        },
        // data: [150, 232, 201, 154, 190, 330, 410, 220],
        data:yAxis4,
      },
    ],
  };
  return option;
};
